<html>
    <head>
        <title>用户登录</title>
    	<meta charset="utf-8">
        <!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css">
        <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
        <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>

        <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
        <script src="http://cdn.bootcss.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    </head>
    <body>
       <div class="container">
          <form class="form-signin">
            <%- message %>
            <h2 class="form-signin-heading">登录</h2>
            <label for="inputEmail" class="sr-only">用户名</label>
            <input type="text" id="inputEmail" class="form-control" placeholder="用户名" required autofocus>
            <label for="inputPassword" class="sr-only">密码</label>
            <input type="password" id="inputPassword" class="form-control" placeholder="请输入密码" required>
            <div class="checkbox">
              <label>
                <input type="checkbox" value="remember-me"> Remember me
              </label>
            </div>
            <button class="btn btn-lg btn-primary btn-block" onclick="login();">登录</button>
          </form>

        </div> <!-- /container -->
    </body>
</html>
<script>
    function login () {
        var username = $('#inputEmail').val();
        var password = $('#inputPassword').val();
        var data = {"username":username,"password":password};
        $.ajax({
            url:'/login',
            type:'POST',
            data:data,
            success: function(data,status) {
                alert(data+"----------"+status);
                if(status == 'success') {
                    location.href = 'home';
                }
            },
            error:function(data,status,e) {
                console.log(data);
                console.log(status);
                if(status == "error") {
                    alert("错误");
                    location.href = 'login';
                }
            }
        });
    }  
</script>